#include "Headers.h"
#include "MFont.h"


MFont::MFont(void)
{
}


MFont::~MFont(void)
{
}

bool MFont::Initialize(int height, int width, int weight, bool italic, bool underline, bool strikeout,
		BYTE charset, BYTE outputprecision, BYTE clipprecision, BYTE quality, BYTE pitchandfamily,
		LPCTSTR fontname)
{
	LOGFONT lf;

	lf.lfHeight = height;
	lf.lfWidth = width;
	lf.lfWeight = weight;
	lf.lfItalic = italic;
	lf.lfUnderline = underline;
	lf.lfStrikeOut = strikeout;
	lf.lfCharSet = charset;
	lf.lfOutPrecision = outputprecision;
	lf.lfClipPrecision = clipprecision;
	lf.lfQuality = quality;
	lf.lfPitchAndFamily = pitchandfamily;
	lstrcpy(lf.lfFaceName, fontname);
	lf.lfOrientation = 0;
	lf.lfEscapement = 0;

	m_Font = CreateFontIndirect(&lf);
	if(m_Font == NULL)
		return false;

	m_TextColor = RGB(255, 255, 255);

	return true;
}

void MFont::UnIntialtize()
{
	DeleteObject(m_Font);
}

void MFont::PrintText(HDC hdc, int x, int y, int width, int height, LPCTSTR text, int count)
{
	HFONT OldFont = NULL;
	RECT rcArea;

	SetRect(&rcArea, x, y, x+width, y+height);
	OldFont = (HFONT)SelectObject(hdc, m_Font);
	
	SetBkMode(hdc, TRANSPARENT);

	SetTextColor(hdc, m_TextColor);
	DrawText(hdc, text, count, &rcArea, DT_WORDBREAK | DT_NOCLIP);

	SelectObject(hdc, OldFont);
}